<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>角色管理</title>
</head>
<body>
<div ng-app="myApp" ng-controller="RoleCtrl">
    <div class="row">
        <ui-container url="system/role/list" key="role-list-00">
            <ui-search-form>
                <search-input class="col-md-2" name="name" placeholder="请输入角色名称"></search-input>
            </ui-search-form>
            <ui-table-tool>
                <a class="btn btn-sm btn-primary" href="system/role/add.htm" >新增</a>
                <a class="btn btn-sm btn-primary" href="javascript:void(0);" onclick="reSet()">重置</a>
            </ui-table-tool>
            <ui-table>

            </ui-table>
            <table-page/>
        </ui-container>
    </div>
</div>
<script>
    angular.module('myApp',['ui.table']);
    angular.module('myApp').controller('RoleCtrl', function($scope){
        function doDel(selectedItems) {
            const uiContainerCtrl=$scope['role-list-00'];
            if(!selectedItems||selectedItems.length<=0){
                toastr.error("没有选中删除对象")
                return;
            }
            const ids = selectedItems.map(m => m.id);
            $.ajax({
                url:'system/role/batchdel',
                data:{ids:ids.join(",")}
            }).done(function (result) {
                if(result.code=='0000'){
                    toastr.success(result.msg);
                    uiContainerCtrl._queryData({});
                }else{
                    toastr.error(result.msg);
                }

            }).fail(function (r) {
                toastr.error("服务器异常"+r);

            });

        }

        $scope.addUser=function (items) {
            console.info(items)
        }
        //每一列的操作按钮
        $scope._operateColumns=[{text:'编辑',click:function (data) {
//            window.open("system/role/update.htm?id="+data.id,"_target");
            window.location.href = "system/role/update.htm?id="+data.id;
        }},{text:'删除',click:function (data) {
            doDel([data])
        }}]
        $scope._columns=[{name:'name',head:'角色名称'},
            {name:'state',head:'激活状态',render(value,data){return value=='0'?'否':'是'}},
            {name:'authorized',head:'可传授',render(value,data){return value=='0'?'否':'是'}},
            {name:'description',head:'描述'}];
        $scope._btns=[{text:'批量删除',click:doDel}];

    });
    function reSet() {
        var reSetObj = $('input');
        var selectObj = $('select');
        reSetObj.val("");
        selectObj.val("");
    }
</script>
</body>
</html>

